package com.cityfood.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cityfood.mapper.CfAdvertisingMapper;
import com.cityfood.pojo.CfAdvertising;
import com.cityfood.pojo.CfAdvertisingExample;
import com.cityfood.pojo.CfStation;
import com.cityfood.pojo.CfAdvertisingExample.Criteria;
import com.cityfood.service.ADService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class ADServiceImpl implements ADService {
	
	@Autowired
	private CfAdvertisingMapper ADMapper;

	@Override
	public List<CfAdvertising> getADBySite(String site) {
		CfAdvertisingExample example=new CfAdvertisingExample();
		Criteria criteria = example.createCriteria();
		criteria.andAdSiteLike("%"+site+"%");
		List<CfAdvertising> list = ADMapper.selectByExample(example);
		return list;
	}
	
	@Override
	public PageInfo<CfAdvertising> getADBySiteAndPage(String site, Integer pageNum) {

		//设置分页的页数和行数
		PageHelper.startPage(pageNum, 20);
		
		CfAdvertisingExample example=new CfAdvertisingExample();
		Criteria criteria = example.createCriteria();
		criteria.andAdSiteLike("%"+site+"%");
		List<CfAdvertising> list = ADMapper.selectByExample(example);
		
		PageInfo<CfAdvertising> info = new PageInfo<>(list);
		return info;
	}


	@Override
	public int insertAD(CfAdvertising advertising) {
		int i = ADMapper.insertSelective(advertising);
		return i;
	}

	@Override
	public int updateAD(CfAdvertising advertising) {
		int i = ADMapper.updateByPrimaryKeySelective(advertising);
		return i;
	}

	@Override
	public int deletetAD(CfAdvertising advertising) {
		advertising.setIsdisplay((byte)0);
		int i = ADMapper.updateByPrimaryKeySelective(advertising);
		return i;
	}

}
